﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace OpenNetCommerce.Localization
{
	public static class MacroSystem
	{
		const string MACRO_MATCH_REGEX_STRING = @"\$[\(\[\{](([a-zA-Z0-9_])+)[\)\]\}]";

		static readonly Regex rex = new Regex(MACRO_MATCH_REGEX_STRING);

		public static Dictionary<string, Func<string>> Macros = new Dictionary<string, Func<string>>();

		public static string Replace(string inputString)
		{
			return rex.Replace(inputString, new MatchEvaluator((Match match) => Macros[match.Groups[1].Value].Invoke()));
		}
	}
}
